package xyz.iguilty.workflow.model;

import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;
import xyz.iguilty.workflow.enums.ProcessLog;

import java.util.HashMap;
import java.util.Map;

/**
 * 任务处理结果
 */
@Getter@Setter
public class DealResult {
    public ProcessLog logType;
    public Map<String, Object> variables = new HashMap<>();
    public static DealResult create(ProcessLog logType,Map<String, Object> variables){
        DealResult result = new DealResult();
        result.setLogType(logType);
        if (!CollectionUtils.isEmpty(variables)) {
            result.getVariables().putAll(variables);
        }
        return result;
    }
    public static DealResult create(Map<String, Object> variables){
        return create(ProcessLog.DEAL,variables);
    }
    public static DealResult create(){
        return create(ProcessLog.DEAL,null);
    }
    public static DealResult create(ProcessLog logType){
        return create(logType,null);
    }
    public void addVariables(Map<String, Object> variables){
        if (!CollectionUtils.isEmpty(variables)) {
            this.getVariables().putAll(variables);
        }
    }
    public DealResult addVariable(String key,Object value){
        if (key != null) {
            this.getVariables().put(key,value);
        }
        return this;
    }
}
